Skip to content

Make a document's text searchable, and read it as soon as it lands - #78

Merged
davior merged 1 commit into
mainfrom
claude/blissful-mayer-viq8yh
Nov 20, 2026
Merged

davior merged 1 commit into
mainfrom
claude/blissful-mayer-viq8yh

Conversation

@davior

@davior davior commented Nov 20, 2026

Copy link
Copy Markdown
Owner

GAM already extracted a document's text into DocumentPage rows, but only when someone pressed Extract text. Nothing searched those rows either, so a phrase on page 74 couldn't be found and Video Creator had nothing to read. This closes the gap recorded in docs/plan-of-attack.md.

What changes

  • Text is read on upload. services/assets._chain_text_extraction queues extract_text for the formats it can read (PDF, DOCX, PPTX, XLSX, TXT/MD/CSV). It always runs, the way music analysis does, because it calls no provider and costs nothing. Formats it can't read (.doc, .odt, …) queue nothing, so they don't leave a red row.
  • Keyword search covers pages. There's a new FTS5 table, page_fts, written by extract_text._store and removed by fts.remove_asset. Its migration (9a3e5d7c1b24) fills it from pages already extracted, so existing documents become searchable on upgrade. Pages get their own table because every reader of segment_fts treats a hit as a transcript segment with a time in seconds.
  • Semantic search covers pages. The embed job now writes one vector per page (owner kind page). Each page is cut to MAX_PAGE_EMBED_CHARS (6,000) before embedding, because one over-long sheet would otherwise fail the whole batch. A finished extraction queues the embed job automatically.
  • A hit names its page. search/hybrid.py carries page_id beside segment_id. GET /api/search hits gain page_id, page_number and page_label, and the search view shows "Page 3" where a timestamp would go.

Video Creator uses this to find a document and read it through the existing GET /api/assets/{id}/text (companion PR in davior/gvc).

Testing

  • pytest -q: 1620 passed. New tests are in tests/test_document_search.py: keyword and semantic hits with their page, the type filter, re-extraction, deletion, ownership, embedding truncation, the chain from extraction to embedding, and the migration backfill (test_migrations.py).
  • Frontend: npm test (523) and npm run build pass.
  • Manual run on a freshly migrated database: uploaded a 3-page PDF with a blank page 2. Text was extracted with nobody pressing anything, and /api/search?q=irrigation&asset_type=document returned the hit labelled "Page 3".

Deploying

This adds a migration. entrypoint.sh runs it under Docker; a bare uvicorn needs alembic upgrade head. Documents uploaded before this change and never extracted still have no text. Run Extract text (bulk works) on them once.


Generated by Claude Code

GAM already extracted a document's text into DocumentPage rows, but only when someone
pressed "Extract text", and nothing searched those rows, so a phrase on page 74 could
not be found and Video Creator had nothing to read. This closes the gap the plan
recorded:

- An upload queues extract_text for the formats it reads. Unconditional, like music
  analysis: it calls nothing and costs nothing.
- Pages are indexed in a new FTS5 table, page_fts, written by extract_text and
  backfilled by its migration from pages already read. Their own table, since every
  reader of segment_fts takes a hit for a transcript segment and a second.
- Pages are embedded (owner kind "page", cut to 6,000 chars so one long sheet cannot
  fail a batch), and a finished extraction chains the embed job.
- Fusion carries a page_id beside segment_id, and a search hit names its page
  (page_id, page_number, page_label). The search view shows it where a timestamp goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V1geD4DSV4uaESBMUTTuRu
@davior
davior marked this pull request as ready for review November 20, 2026 13:48
@davior
davior merged commit 2efde86 into main Nov 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants